package exttable.timetable.models;

import utils.Localisation;

import javax.swing.table.AbstractTableModel;
import java.util.List;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Apr 12, 2010
 * Time: 3:50:13 PM
 * To change this template use File | Settings | File Templates.
 */
public class AnalysCheckerTableModel extends AbstractTableModel {
    public static final int ANALYSIS_ID = 0;
    public static final int ANALYSIS_NAME = 1;

    private List<AnalysisModel> data;
    private Vector<VisitModel> columns;
    private Boolean[][] rowData;

    public AnalysCheckerTableModel(List<AnalysisModel> data, Vector<VisitModel> columns) {
        this.data = data;
        this.columns = columns;
        this.rowData = new Boolean[data.size()][columns.size()];
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columns.size() + 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        AnalysisModel am = data.get(rowIndex);
        switch (columnIndex) {
            case ANALYSIS_ID:
                return am.getAnalysis().getAnalysisId();
            case ANALYSIS_NAME:
                return am.getAnalysis();
            default:
                return rowData[rowIndex][columnIndex - 2];

        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case ANALYSIS_ID:
                return Integer.class;
            case ANALYSIS_NAME:
                return String.class;
            default: {
                return Boolean.class;
            }
        }
    }

    @Override
    public String getColumnName(int column) {
        if (column == ANALYSIS_ID) {
            return Localisation.getMessage("timetable.analysid");
        }
        if (column == ANALYSIS_NAME) {
            return Localisation.getMessage("timetable.analysname");
        } else {
            return String.valueOf(columns.get(column - 2).getVisit() + " " + Localisation.getMessage("timetable.days") + " " + columns.get(column - 2).getDays());
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        if (columnIndex > 1) {
            rowData[rowIndex][columnIndex - 2] = Boolean.valueOf(aValue.toString());
            fireTableCellUpdated(rowIndex, columnIndex - 2);
        }
    }
}
